package com.toe.business.webapi.controller;


import com.toe.business.service.BusinessInformationService;
import com.toe.common.restful.JsonPage;
import com.toe.common.restful.JsonResult;
import com.toe.pojo.dto.business.BusinessInfoUpdateDTO;
import com.toe.pojo.vo.business.BusinessInfoDetailsVO;
import com.toe.pojo.vo.business.BusinessInfoId;
import com.toe.pojo.vo.business.BusinessInfoShowVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 陶涛
 * @since 2022-07-19
 */
@RestController
@RequestMapping("/webapi/business-information")
@Api(tags = "商家模块")
public class BusinessInformationController {
    @Autowired
    private BusinessInformationService businessService;

    @GetMapping("/page")
    @ApiOperation("分页查询商家")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "页码",name="pageNum",example = "1"),
            @ApiImplicitParam(value = "每页条数",name="pageSize",example = "8")
    })
    public JsonResult<JsonPage<BusinessInfoShowVO>> pageOrders(Integer pageNum, Integer pageSize){
        // 分页调用
        JsonPage<BusinessInfoShowVO> jsonPage=businessService.getAllBusinessByPage(pageNum,pageSize);
        return JsonResult.ok(jsonPage);
    }

    @GetMapping("/de-InfoById")
    @ApiOperation("商家详细信息")
    public JsonResult<BusinessInfoDetailsVO> detailsInfo(Long id){
        BusinessInfoDetailsVO listDetails = businessService.businessInfoDetails(id);
        return JsonResult.ok(listDetails);
    }

    @GetMapping("/order-businessId")
    @ApiOperation("商家ID和商家name")
    public JsonResult<List<BusinessInfoId>> businessIds(){
        List<BusinessInfoId> ids = businessService.businessIds();
        return JsonResult.ok(ids);
    }

    @PostMapping("/updateBusinessInfo")
    @ApiOperation("商家修改个人信息")
    public JsonResult<Void> updateBusinessInfo(@RequestBody @Validated BusinessInfoUpdateDTO business){
        businessService.updateBusinessInfo(business);
        return JsonResult.ok();
    }


}

